<?php
/*
 *  @author Nicolas Genevaux
 * (c)nige 2008
 */
	include_once($RACINE.'inc/fct.basedonnee.php');
	include_once($RACINE.'inc/fct.utils.php');
	include_once($RACINE.'inc/sql.questionnaire.php');
	include_once($RACINE.'inc/sql.exercicerealise.php');
	include_once($RACINE.'inc/sql.inscrit.php');
	$IDMATIERE = $_SESSION['IDMATIEREDETAIL'];
	include($RACINE.'inc/var.points.php');
	if(!$_SESSION['questions']) {
		if((($INSCRIT->points > $TESTS)||(!$_SESSION['ID_CONECT']>0))&& $_SESSION['ID_TEST']>0) {
			doSQL($INSCRIT_POINTS,array(0=>"'".$_SESSION['ID_CONECT']."'",1=>"(".(-1)*$TESTS.")"));
			if($_SESSION['IDMATIEREDETAIL'] > 0) {
				$questions = doSQLArray($QUESTIONNAIRE_ADAPTE,array(0=>$_SESSION['IDMATIEREDETAIL'],1=>$_SESSION['ID_CONECT'],2=>$_SESSION['MATIEREDETAILLEVEL']));
				if(!$questions[0]) {
					$questions = doSQLArray($QUESTIONNAIRE_ADAPTE_ALL,array(0=>$_SESSION['IDMATIEREDETAIL'],1=>$_SESSION['ID_CONECT'],2=>$_SESSION['MATIEREDETAILLEVEL']));
				}
			}
			else {
				$questions = doSQLArray($QUESTIONNAIRE_SELECT_ALL);
			}
			$_SESSION['questions'] = $questions;
			$_SESSION['questioncourante'] = -1;
			$_SESSION['score'] = 0;
			$_SESSION['questionOK'] = 0;
			$_SESSION['IDMATIEREDETAIL'] = "";
			$_SESSION['MATIEREDETAILLEVEL'] = "";
		}
		else {
			redirect($PAGE_ACCUEIL_INSCRIT);
		}
	}
	else {
		if($_SESSION['questioncourante']<40) {
			if($_SESSION['questions'][$_SESSION['questioncourante']]['reponse']==$_POST['reponse']) {
				$_SESSION['score'] += (1/$_POST['compteur']*5 > 1)? 1 : 1/$_POST['compteur']*5;
				$_SESSION['questions'][$_SESSION['questioncourante']]['reussi']=1;
				$_SESSION['questionOK']++;
			}
			else {
				$_SESSION['questions'][$_SESSION['questioncourante']]['reussi']=0;
			}
			$_SESSION['questions'][$_SESSION['questioncourante']]['compteur']=$_POST['compteur'];
			doSQL($EXERCICEREALISE_RECORD,array(0=>$_SESSION['questions'][$_SESSION['questioncourante']]['identifiant'],1=>$_SESSION['ID_TEST'],2=>$_SESSION['questions'][$_SESSION['questioncourante']]['reussi'],3=>$_SESSION['questions'][$_SESSION['questioncourante']]['compteur']));
		}
		if($_SESSION['questioncourante']>38) {
			for($i=0;$_SESSION['questions'][$i];$i++) {
				$courbeEvolution[$i] = $_SESSION['questions'][$i]['reussi']/($_SESSION['questions'][$i]['compteur']+1)*5;
			}
			$_SESSION['courbeEvolution'] = $courbeEvolution;
			redirect($PAGE_TEST_RESULT);
		}
	}
	$_SESSION['questioncourante']++;
?>
